**********************************************************************
** Hou et al. SMJ 2023: To construct supplement, figures and tables **
**********************************************************************


*****prepare******
clear all
set more off
global gdrive: env google 
global nbox: env nBox
global gdrive: env google 
global stata "stata"
global stataout "stata-out\Strt"
global date : di %tdCCYYNNDD date(c(current_date), "DMY") 
global patent "Patent"
global seed 20211013
global reps 1000
global outopt landscape plain coljust(lc) var se starloc(1) ///
  starlevels(10 5 1)  bdec(3) 
global outfile strt_pub


use "strt_cont.dta", clear
global ctrvar emp_ln revt_per_inh ppe_per_inh   
global sample if manuf == 1
drop if year >= 1983 & year <= 1985

capture program drop pat_reg
program define pat_reg
 local chi2:  display %6.2f  `e(chi2)' 
 gen sample = e(sample)
 unique gvkey if sample == 1
 local cmp: display %6.0f `r(unique)'
 unique pdpass if sample == 1 
 local pd: display %6.0f `r(unique)'
 
 lincom CAFC*($mean_post - $mean_pre)
 local est = r(estimate)
 local psave =  r(p) 
 local pvalue: display %6.3f `psave'
 local change = (exp(`est') - 1)*100
 local perct: display %6.1f `change'
 local obs: display %6.0f `e(N)'
 local r2: display %6.2f `r(r2_a)'
 drop sample
 

 
outreg, $outopt  merge(table) ///
 ctitle( "VARIABLES", "`1'"  ) ///
 addrows( "P value for CAFC", "`pvalue'" \ "Business-circuit FE", "Yes" ///
  \ "Year FE", "Yes" \  ///
  "Businesses", "`pd'" \ "Companies", "`cmp'" \  ///
  "Observation", "`obs'" \  "Adjusted R-squared", "`r2'"  \ ///
   "Chi-squared", "`chi2'"    \   "CAFC economic effect", "`perct'%" )
end


preserve 
use "CAFC_ct_updated.dta", clear
sum ratepre_all_wt
global mean_pre = r(mean)
sum ratepost_all_wt
global mean_post = r(mean)
restore
global sample if manuf == 1
ppmlhdfe npat CAFC $ctrvar  $sample , ///
    absorb(year pd_ct) cluster(circuit gvkey)  d

keep if e(sample)


******************************
** Table C3. Forum shopping **
******************************

xi: bootstrap, cluster(circuit gvkey) seed($seed) reps($reps): ///
ppmlhdfe strt_yes CAFC $ctrvar, a(pd_ct year)
pat_reg "(a) Preferred estimate"

preserve 
use "CAFC_ct_updated.dta", clear
sum ratepre_all_wt
global mean_pre = r(mean)
sum ratepost_all_wt
global mean_post = r(mean)
restore
gen CAFC_wt = ratepre_all_wt 
replace CAFC_wt =  ratepost_all_wt if year >= 1986
replace CAFC = CAFC_wt
xi: bootstrap, cluster(circuit gvkey) seed($seed) reps($reps): ///
ppmlhdfe strt_yes CAFC $ctrvar if manuf == 1  , a(pd_ct year)
pat_reg "(b) Weighted CAFC index"

preserve 
use "CAFC_ct_updated.dta", clear
sum ratepre_home
global mean_pre = r(mean)
sum ratepost_home
global mean_post = r(mean)
restore
replace CAFC = CAFC2

xi: bootstrap, cluster(circuit gvkey) seed($seed) reps($reps): ///
ppmlhdfe strt_yes CAFC $ctrvar if manuf == 1  , a(pd_ct year)
pat_reg "(c) Home circuit CAFC strategic"
 
preserve 
use "CAFC_ct_updated.dta", clear
sum ratepre_all
global mean_pre = r(mean)
sum ratepost_all, de
global mean_post = r(mean)
restore
replace CAFC = CAFC1 
outreg, clear(table)
xi: bootstrap, cluster(circuit gvkey) seed($seed) reps($reps): ///
ppmlhdfe strt_yes CAFC $ctrvar if manuf == 1 & year <= 1990 , a(pd_ct year)
pat_reg "(d) Sample period up to 1990"

xi: bootstrap, cluster(circuit gvkey) seed($seed) reps($reps): ///
ppmlhdfe strt_yes CAFC $ctrvar if manuf == 1 & circuit != 3 & circuit != 8, a(pd_ct year)
pat_reg "(e) Exclude 3rd and 8th Circuits"

cd "$stataout"
outreg using "$outfile.doc", $outopt ///
replay(table) addt title("Forum shopping") ///
note("$note") 



******************************************************************************
** Table D1. Strategic patenting: Alternative measures of strategic patents **
******************************************************************************

outreg, clear(table)

xi: bootstrap, cluster(circuit gvkey) seed($seed) reps(10): ///
ppmlhdfe strt_yes CAFC $ctrvar, a(pd_ct year)
pat_reg "(a) Preferred estimate"

xi: bootstrap,  seed($seed) reps($reps): ///
ppmlhdfe CON_DIV CAFC    $ctrvar if manuf == 1, ///
    absorb(year pd_ct)  cluster(circuit gvkey)
pat_reg  "(b) Exclude CIP"

xi: bootstrap,  seed($seed) reps($reps): ///
ppmlhdfe parent_yes CAFC    $ctrvar if manuf == 1, ///
    absorb(year pd_ct)  cluster(circuit gvkey)
pat_reg  "(c) Parents"

xi: bootstrap,  seed($seed) reps($reps): ///
ppmlhdfe pat_strt_val_1 CAFC    $ctrvar if manuf == 1, ///
    absorb(year pd_ct)  cluster(circuit gvkey)
pat_reg  "(d) High commercial + low technological value"

cd "$stataout"
outreg using "$outfile.doc", $outopt ///
 replay(table) addt title("Robustness") ///

 
*********************************************** 
** Table D2. Robustness: Sample construction **
*********************************************** 

outreg, clear(table)
xi: bootstrap, cluster(circuit gvkey) seed($seed) reps(10): ///
ppmlhdfe strt_yes CAFC $ctrvar, a(pd_ct year)
pat_reg "(a) Preferred estimate"

 use "strt_cont.dta", clear
global ctrvar emp_ln revt_per_inh ppe_per_inh   
global sample if manuf == 1
preserve 
use "CAFC_ct_updated.dta", clear
sum ratepre_all_wt
global mean_pre = r(mean)
sum ratepost_all_wt
global mean_post = r(mean)
restore
global sample if manuf == 1
ppmlhdfe npat CAFC $ctrvar  $sample , ///
    absorb(year pd_ct) cluster(circuit gvkey)  d

keep if e(sample)
xi: bootstrap, cluster(circuit gvkey) seed($seed) reps(10): ///
ppmlhdfe strt_yes CAFC $ctrvar, a(pd_ct year)
pat_reg "(b) Include 1983-1985"
 use "strt_cont.dta", clear
global ctrvar emp_ln revt_per_inh ppe_per_inh   
global sample if manuf == 1
drop if year >= 1983 & year <= 1985
preserve 
use "CAFC_ct_updated.dta", clear
sum ratepre_all_wt
global mean_pre = r(mean)
sum ratepost_all_wt
global mean_post = r(mean)
restore
global sample if manuf == 1
ppmlhdfe npat CAFC $ctrvar  $sample , ///
    absorb(year pd_ct) cluster(circuit gvkey)  d

keep if e(sample)
xi: bootstrap, cluster(circuit gvkey) seed($seed) reps(10): ///
ppmlhdfe strt_yes CAFC $ctrvar if year != 1981 , a(pd_ct year)
pat_reg "(c) Exclude 1981"

xi: bootstrap, cluster(circuit gvkey) seed($seed) reps($reps): ///
ppmlhdfe strt_yes CAFC $ctrvar if manuf == 1 & cmp_statecode != "CA", a(pd_ct  year)
pat_reg "(d) Excluding CA"
 
 
 
**************************************** 
** Table E1. Alternative explanations **
****************************************
 
outreg, clear(table)
xi: bootstrap,  seed($seed) reps($reps): ///
reghdfe mean_claims_inh  CAFC  $ctrvar  if manuf == 1, ///
    absorb(year pd_ct)  cluster(circuit gvkey)
pat_reg  "(a) Average number of claims"
 
xi: bootstrap,  seed($seed) reps($reps): ///
ppmlhdfe ct_clm_mean CAFC  va1_sum_ln  va12_perct $ctrvar if manuf == 1, ///
    absorb(year pd_ct)  cluster(circuit gvkey)
pat_reg  "(b) Average independent claim count"
 
xi: bootstrap,  seed($seed) reps($reps): ///
reghdfe wrd_min_mean_ln  CAFC  $ctrvar  if manuf == 1, ///
    absorb(year pd_ct)  cluster(circuit gvkey)
pat_reg  "(c) Average independent claim length"
 
xi: bootstrap,  seed($seed) reps($reps): ///
ppmlhdfe strt_yes CAFC  va1_sum_ln  va12_perct $ctrvar if manuf == 1, ///
    absorb(year pd_ct)  cluster(circuit gvkey)
pat_reg  "(d) Industry structure"
 
xi: bootstrap,  seed($seed) reps($reps): ///
ppmlhdfe strt_yes CAFC utsan_sum_ct  $ctrvar    if manuf == 1, ///
    absorb(year pd_ct)   cluster(circuit gvkey)
pat_reg  "(e) Trade secrecy"	
 
 
 
